package com.yang.doctorrecruitment.action;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.GetUserResumeDAO;
import com.yang.doctorrecruitment.dto.UserResume;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class ShowUserResumeAction extends ActionSupport{
    //这里拿到了ID,根据ID加载相关的数据
    private String UserID;
    private JSON baseInfomation;
    private JSON jobIntension;
    private JSON workExperience;
    private JSON projectExperience;
    private JSON educationExperience;
    private JSON schoolSituation;
    private JSON skills;
    private JSON appendInformation;
    private JSON extraresume;
    public JSON getJobIntension() {
        return jobIntension;
    }

    public void setJobIntension(JSON jobIntension) {
        this.jobIntension = jobIntension;
    }

    public JSON getWorkExperience() {
        return workExperience;
    }

    public void setWorkExperience(JSON workExperience) {
        this.workExperience = workExperience;
    }

    public JSON getProjectExperience() {
        return projectExperience;
    }

    public void setProjectExperience(JSON projectExperience) {
        this.projectExperience = projectExperience;
    }

    public JSON getEducationExperience() {
        return educationExperience;
    }

    public void setEducationExperience(JSON educationExperience) {
        this.educationExperience = educationExperience;
    }

    public JSON getSchoolSituation() {
        return schoolSituation;
    }

    public void setSchoolSituation(JSON schoolSituation) {
        this.schoolSituation = schoolSituation;
    }

    public JSON getSkills() {
        return skills;
    }

    public void setSkills(JSON skills) {
        this.skills = skills;
    }

    public JSON getAppendInformation() {
        return appendInformation;
    }

    public void setAppendInformation(JSON appendInformation) {
        this.appendInformation = appendInformation;
    }

    public JSON getBaseInfomation() {
        return baseInfomation;
    }

    public void setBaseInfomation(JSON baseInfomation) {
        this.baseInfomation = baseInfomation;
    }

    public JSON getExtraresume() {
        return extraresume;
    }

    public void setExtraresume(JSON extraresume) {
        this.extraresume = extraresume;
    }

    public String getUserID() {
        return UserID;
    }

    public void setUserID(String userID) {
        UserID = userID;
    }

    public String ShowUserResume() throws IOException {
        //执行数据库的相关操作，我首先要确定ajax能够访问到这个action并且拿到相关的参数。
        JSONObject jsonObject=new JSONObject();
        HttpServletRequest request= (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
        String userid=request.getParameter("UserID");
        UserResume userResume= GetUserResumeDAO.getUserResume(userid);
        baseInfomation=JSONObject.parseObject(userResume.getBaseInfomation());
        jobIntension= JSONArray.parseObject(userResume.getJobIntension());
        workExperience=JSONObject.parseObject(userResume.getWorkExperience());
        projectExperience= JSONArray.parseObject(userResume.getProjectExperience());
        educationExperience=JSONObject.parseObject(userResume.getEducationExperience());
        schoolSituation= JSONArray.parseObject(userResume.getSchoolSituation());
        skills=JSONObject.parseObject(userResume.getSkills());
        appendInformation= JSONArray.parseObject(userResume.getAppendInformation());
        JSONObject object=new JSONObject();
        if(userResume.getExtraResume()!=null){
            object.put("extraresume",userResume.getExtraResume());
        }else{
            object.put("extraresume","-1");
        }
        extraresume=object;
        return SUCCESS;
    }
}
